﻿using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_145 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 1000000000;
            //const int max = 1000;

            long res = 0;

            for (long n = 10; n <= max; n++)
            {
                if (n%10 == 0)
                    continue;
                var val = n;
                long nr = 0;
                while (val > 0)
                {
                    nr = 10*nr + val%10;
                    val /= 10;
                }
                val = nr+ n;
                var ex = false;
                while (val > 0)
                {
                    if (val %2==0)
                    {
                        ex = true;
                        break;
                    }
                    val /= 10;
                }

                if (!ex)
                    res++;

            }
            return res;
        }

        public override string Problem
        {
            get
            {
                return @"Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).

There are 120 reversible numbers below one-thousand.

How many reversible numbers are there below one-billion (109)?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 608720;
            }
        }

    }
}
